<?php
include("code/databaseconnection.php");

include("header.php");
?>
<?php
if($_GET['action']=="delete")
{
	$id=$_GET['id'];
	mysql_query("DELETE FROM designation WHERE ID='".$id."'") or die(mysql_error());	
	echo '<font color="#FF0000" size="6" >User id  '.$id.' Deleted</font>';
}

if($_GET['action']=="edit")
{
	$id=$_GET['id'];
	$rowresult=mysql_query("SELECT * FROM designation WHERE ID='".$id."'  ") or die(mysql_error());
	$row=mysql_fetch_array($rowresult);
	$db_designation_name = $row['NAME_DESIGNATION'];
	$db_description = $row['DESCRIPTION'];
	

?>
<form action="designation_manage.php?action=update&id=<?php  echo $id ?>" method="post">
<table width="600" cellspacing="0" cellpadding="0">

<tr>
      <td>designation</td>
      <td><input type="text" name="designation" size="30" value="<?php echo $db_designation_name; ?>"  /></td>
</tr>
    
<tr>
      <td>Discription</td>
      <td><input type="text" name="Discription" size="30" value="<?php echo  $db_description; ?>"  /></td>
</tr>
    
<tr>
    <td></td>
    <td> <input type="submit" name="submit" value="update" ></td>
  </tr>
</table>
</form>

<?php
}
if($_GET['action']=="update")
{
	$id=$_GET['id'];
	$g_designation = $_POST['designation'];
	$g_description = $_POST['Discription'];
	mysql_query(" UPDATE designation SET NAME_DESIGNATION='".$g_designation."',DESCRIPTION='".$g_description."' WHERE ID='".$id."' ") or die(mysql_error());
	echo '<font color="#00CC00" size="+3" >Updated</font>';
	
}
if($_GET['action']=="")
{
$result=mysql_query("SELECT * FROM designation ");
$total = mysql_num_rows($result);
$i=0;

echo '<table width="600" border="1"> 
<tr><td>designation_NAME</td>
	<td>DESCRIPTION</td>
	<td>Edit</td>
	<td>Delete</td>
</tr>';
	while ($i < $total)
	{
		$row=mysql_fetch_array($result);
		$db_designation_name = $row['NAME_DESIGNATION'];
		$db_description = $row['DESCRIPTION'];
		$db_id = $row['ID'];
		
		echo "
		<tr>
	<td>".$db_designation_name."</td>
	<td>".$db_description."</td>
    
    
	<td><a href='?action=edit&id=".$row['ID']."' ><img border=0 src='edit.png' /></a>
	</td>
	<td>
	 <a href='?action=delete&id=".$row['ID']."' >
	 <img src='delete.png' border='0' />
	 </a>
	 </td>
</tr>";
		$i++;
		}
	echo "</table>";
	
}
?>
<?php 
include("fooder.php");
?>